home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3489 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: Rezonet.net!news
  2. From: ray@ultimate-tech.com (Ray Dunn)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: 29 Jan 1996 14:03:14 GMT
  6. Organization: Ultimate Technographics Inc.
  7. Message-ID: <4eik32$15mb@ns.RezoNet.NET>
  8. References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov> <4e6rs0$dvl@ns.RezoNet.NET> <9601251245.AA12220@dxmint.cern.ch> <822791542snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: 204.19.230.7
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In referenced article, Lawrence Kirby says...
  15. >Two's complement is a representation for signed integers so
  16. >unsigned arithmetic clearly doesn't use it. However the nice thing 
  17. >about 2's complement arithmetic is that in most instances the 
  18. >underlying bit manipulations are (or can be for a suitable definition 
  19. >of overflow behaviour) the same as those for unsigned arithmetic (so 
  20. >at the archetecture level a single form of, e.g. an ADD instruction, 
  21. >can deal with both).
  22. >
  23. >So the expression (-5) and (-5U) are each evaluated by its own set of 
  24. >rules but where signed integers are represented in 2's complement the 
  25. >2 results will have the same underlying bit pattern.
  26.  
  27. So what would you call this operation that is being done on the 
  28. unsigned int?
  29.  
  30. I really think you're nit-picking unnecessarily here, so let me 
  31. nit-pick back... (:-)
  32.  
  33. Dan Pop's assertion that unary minus does a two's complement negate on 
  34. unsigned types in 'C' was a perfectly reasonable statement.
  35.  
  36. A two's complement negate is a bitwise operation on a set of bits, just 
  37. like a one's complement negate is.  The signedness of that set of bits 
  38. is irrelvant to the operation, like any other, it is only the 
  39. subsequent interpretation of the sign bit that matters.
  40. -- 
  41. Ray Dunn (opinions are my own) | Phone: (514) 938 9050
  42. Montreal                       | Phax : (514) 938 5225
  43. ray@ultimate-tech.com          | Home : (514) 630 3749
  44.  
  45.